package com.linkhub.oms.data.sync.api.wms.domain.request;

import com.alibaba.fastjson.annotation.JSONField;
import com.linkhub.oms.common.util.QtBeanUtil;
import com.linkhub.oms.data.sync.api.wms.domain.dto.WmsCancelOrderDTO;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;


/**
 * @author Jaycle
 * @version 1.0.0
 * @Description BatchCancelOrderRequest.java
 * @createTime 2024/06/16 11:24
 */
@NoArgsConstructor
@Data
public class BatchCancelOrderRequest implements Serializable {

    public static BatchCancelOrderRequest createRequest( WmsCancelOrderDTO dto ) {
        BatchCancelOrderRequest request = new BatchCancelOrderRequest();
        request.setRequest(new Request());

        // Copy properties from dto to request
        QtBeanUtil.copyProperties(dto, request.getRequest());

        // Convert orders if necessary
        if (dto.getOrders() != null) {
            List<Request.Orders.Order> orderList = new ArrayList<>();
            for (WmsCancelOrderDTO.Order wmsOrder : dto.getOrders()) {
                Request.Orders.Order order = new Request.Orders.Order();
                QtBeanUtil.copyProperties(wmsOrder, order);
                orderList.add(order);
            }

            Request.Orders orderss = new Request.Orders();
            orderss.setOrder(orderList);
            request.getRequest().setOrders(orderss);
        }

        return request;
    }

    /**
     * request
     */
    @JSONField(name = "request")
    private Request request;

    @NoArgsConstructor
    @Data
    public static class Request {
        /**
         * outBizCode
         */
        @JSONField(name = "outBizCode")
        private String outBizCode;

        /**
         * orders
         */
        @JSONField(name = "orders")
        private Orders orders;

        @NoArgsConstructor
        @Data
        public static class Orders {
            /**
             * order
             */
            @JSONField(name = "order")
            private List<Order> order;

            @NoArgsConstructor
            @Data
            public static class Order {
                /**
                 * warehouseCode
                 */
                @JSONField(name = "warehouseCode")
                private String warehouseCode;

                /**
                 * ownerCode
                 */
                @JSONField(name = "ownerCode")
                private String ownerCode;

                /**
                 * orderCode
                 */
                @JSONField(name = "orderCode")
                private String orderCode;

                /**
                 * orderId
                 */
                @JSONField(name = "orderId")
                private String orderId;

                /**
                 * cancelReason
                 */
                @JSONField(name = "cancelReason")
                private String cancelReason = "Manual Cancel";

                /**
                 * cancelType
                 */
                @JSONField(name = "cancelType")
                private String cancelType;
            }
        }
    }
}
